]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st: Use template material for transitions
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 11 Sep 2010 22:18:52 +0000 (00:18 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 13 Sep 2010 15:50:05 +0000 (17:50 +0200)
To avoid compiling a new shader each time a transition is started,
use a copy of a static template material.

See http://bugzilla.clutter-project.org/show_bug.cgi?id=2280#c5.

https://bugzilla.gnome.org/show_bug.cgi?id=629384

src/st/st-theme-node-transition.c

index 884f806ae0716fda792249873cf4050f5f0fed0c..e523c5ce32729e395415b74c6ca9980d0017cf7a 100644 (file)
@@ -55,6 +55,9 @@ struct _StThemeNodeTransitionPrivate {
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
+/* template material to avoid unnecessary shader compilation */
+static CoglHandle global_material = COGL_INVALID_HANDLE;
+
 G_DEFINE_TYPE (StThemeNodeTransition, st_theme_node_transition, G_TYPE_OBJECT);
 
 
@@ -244,21 +247,27 @@ setup_framebuffers (StThemeNodeTransition *transition,
   g_return_val_if_fail (priv->old_offscreen != COGL_INVALID_HANDLE, FALSE);
   g_return_val_if_fail (priv->new_offscreen != COGL_INVALID_HANDLE, FALSE);
 
-  if (priv->material)
-    cogl_handle_unref (priv->material);
-  priv->material = cogl_material_new ();
-
-  cogl_material_set_layer_combine (priv->material, 0,
-                                   "RGBA = REPLACE (TEXTURE)",
-                                   NULL);
-  cogl_material_set_layer_combine (priv->material, 1,
-                                   "RGBA = INTERPOLATE (PREVIOUS, "
-                                                       "TEXTURE, "
-                                                       "CONSTANT[A])",
-                                   NULL);
-  cogl_material_set_layer_combine (priv->material, 2,
-                                   "RGBA = MODULATE (PREVIOUS, PRIMARY)",
-                                   NULL);
+  if (priv->material == NULL)
+    {
+      if (G_UNLIKELY (global_material == COGL_INVALID_HANDLE))
+        {
+          global_material = cogl_material_new ();
+
+          cogl_material_set_layer_combine (global_material, 0,
+                                           "RGBA = REPLACE (TEXTURE)",
+                                           NULL);
+          cogl_material_set_layer_combine (global_material, 1,
+                                           "RGBA = INTERPOLATE (PREVIOUS, "
+                                                               "TEXTURE, "
+                                                               "CONSTANT[A])",
+                                           NULL);
+          cogl_material_set_layer_combine (global_material, 2,
+                                           "RGBA = MODULATE (PREVIOUS, "
+                                                            "PRIMARY)",
+                                           NULL);
+        }
+      priv->material = cogl_material_copy (global_material);
+    }
 
   cogl_material_set_layer (priv->material, 0, priv->new_texture);
   cogl_material_set_layer (priv->material, 1, priv->old_texture);